From d5be6bf3fbe73588697866676514369fd8f4e784 Mon Sep 17 00:00:00 2001
From: Yann Dirson <ydirson@o-computers.com>
Date: Wed, 13 Jan 2016 17:00:35 +0100
Subject: [PATCH 10/27] Import GMAC_PHY_POWER support from the loboris source
 tree.

Signed-off-by: Yann Dirson <ydirson@o-computers.com>
---
 drivers/net/ethernet/sunxi/eth/Kconfig      |  8 +++++++
 drivers/net/ethernet/sunxi/eth/sunxi_geth.c | 35 +++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/drivers/net/ethernet/sunxi/eth/Kconfig b/drivers/net/ethernet/sunxi/eth/Kconfig
index 13787db..af930df 100755
--- a/drivers/net/ethernet/sunxi/eth/Kconfig
+++ b/drivers/net/ethernet/sunxi/eth/Kconfig
@@ -35,5 +35,13 @@ config GETH_PHY_POWER
 	 If external PHY power is exist, and it want to be controled,
 	 select it.  If not, it mean the power of PHY already on.
 
+config GMAC_PHY_POWER
+        bool "External PHY power control"
+	depends on SUNXI_GETH
+	default y
+	---help---
+	 If external PHY power is exist, and it want to be controled,
+	 select it.  If not, it mean the power of PHY already on.
+
 endif
 
diff --git a/drivers/net/ethernet/sunxi/eth/sunxi_geth.c b/drivers/net/ethernet/sunxi/eth/sunxi_geth.c
index 7c48f7b..03931f2 100755
--- a/drivers/net/ethernet/sunxi/eth/sunxi_geth.c
+++ b/drivers/net/ethernet/sunxi/eth/sunxi_geth.c
@@ -154,6 +154,9 @@ struct geth_priv {
 
 	spinlock_t lock;
 	spinlock_t tx_lock;
+#ifdef CONFIG_GMAC_PHY_POWER
+	u32 gpio_power_hd;
+#endif
 };
 
 #ifdef CONFIG_GETH_PHY_POWER
@@ -195,6 +198,11 @@ static void desc_print(struct dma_desc *desc, int size)
 static int geth_power_on(struct geth_priv *priv)
 {
 	int value;
+
+#ifdef CONFIG_GMAC_PHY_POWER
+	gpio_set_value(priv->gpio_power_hd, 1);
+#endif
+
 #ifdef CONFIG_GETH_PHY_POWER
 	struct regulator **regu;
 	int ret = 0, i = 0;
@@ -258,6 +266,11 @@ err:
 static void geth_power_off(struct geth_priv *priv)
 {
 	int value;
+
+#ifdef CONFIG_GMAC_PHY_POWER
+	gpio_set_value(priv->gpio_power_hd, 0);
+#endif
+
 #ifdef CONFIG_GETH_PHY_POWER
 	struct regulator **regu = priv->power;
 	int i = 0;
@@ -1608,6 +1621,12 @@ static int geth_sys_request(struct platform_device *pdev)
 	int ret = 0;
 	struct resource *res;
 
+#ifdef CONFIG_GMAC_PHY_POWER
+	script_item_value_type_e  type;
+	script_item_u item;
+	int req_status;
+#endif
+
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "geth_extclk");
 	if (unlikely(!res)){
 		ret = -ENODEV;
@@ -1681,6 +1700,22 @@ static int geth_sys_request(struct platform_device *pdev)
 		}
 	}
 #endif
+
+#ifdef CONFIG_GMAC_PHY_POWER && CONFIG_GETH_SCRIPT_SYS
+	type = script_get_item("gmac_phy_power", "gmac_phy_power_en", &item);
+	if (SCIRPT_ITEM_VALUE_TYPE_PIO != type) {
+		pr_err("script_get_item return type err\n");
+		return -EFAULT;
+	}
+	/*request gpio*/
+	req_status = gpio_request(item.gpio.gpio, NULL);
+	if (0 != req_status) {
+		pr_err("request gpio failed!\n");
+	}
+	gpio_direction_output(item.gpio.gpio, 1);
+	priv->gpio_power_hd = item.gpio.gpio;
+ #endif
+
 	return 0;
 
 pin_err:
-- 
1.9.1

